<template>
  <div>
    <div class="dashboard-container">
      

      <div class="big-back-box">
        <div class="top" style="margin-bottom: 20px">求助信息修改</div>
        <!-- 卡片 -->
        <div style="width: 600px; margin: 0 auto">
          <el-form ref="form" :model="form" label-width="80px">            
            <!--  -->
            <el-form-item label="id">
              <el-input v-model="form.id"></el-input>
            </el-form-item>
            <!--  -->
            <el-form-item label="buyerId">
              <el-input v-model="form.buyerId"></el-input>
            </el-form-item>

            <!-- 求助标题 -->
            <el-form-item label="求助标题">
              <el-input v-model="form.title"></el-input>
            </el-form-item>
            <!-- 求助类型 -->
            <el-form-item label="求助类型">
              <el-select v-model="form.type" placeholder="请选择求助类型">
                <el-option label="类型A" value="typeA"></el-option>
                <el-option label="类型B" value="typeB"></el-option>
              </el-select>
              <span>this.form.type: {{ this.form.type }}</span>
            </el-form-item>
            <!-- 所在地区 -->
            <el-form-item label="地区">
              <el-input v-model="form.region"></el-input>
            </el-form-item>
            <!-- 内容 -->
            <el-form-item label="内容">
              <el-input
                type="textarea"
                v-model="form.content"
                rows="5"
              ></el-input>
            </el-form-item>
            <!-- 价格 -->
            <!-- <el-form-item label="价格" style="width: 1000px">
              <span style="margin-left: 10px; font-size: 15px; color: red"
                ><b>500元</b></span
              >
            </el-form-item> -->

            <!-- 按钮 -->
            <el-form-item>
              <router-link to="/lawHelp/customerHelpList">
              <el-button type="primary" @click="saveHelp">确认</el-button>
              </router-link>
              <router-link to="/lawHelp/customerHelpList">
                <el-button>取消</el-button>
              </router-link>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 获取当前登录账户信息
import { returnUserInformation } from "@/api/user.js";
// 新增法律求助信息
import { modifyLegalRecourse } from "@/api/lawHelp.js";

export default {
  data() {
    return {
      size: "",
      form: {},
      price: "100元",
    };
  },
  // 初始化
  mounted() {
    // 接收传参
    console.log("this.$route.query" + this.$route.query);
    this.form = this.$route.query;
    console.log("this.form.id: "+this.form.id);
  },
  methods: {
    // 获取当前时间
    getInitiationTime() {
      var standardDate = new Date();
      console.log(standardDate); //Wed Aug 21 2019 10:00:58 GMT+0800 (中国标准时间)
      this.form.initiationTime =
        standardDate.getFullYear() +
        "-" +
        (standardDate.getMonth() + 1) +
        "-" +
        standardDate.getDate() +
        " " +
        standardDate.getHours() +
        ":" +
        standardDate.getMinutes() +
        ":" +
        standardDate.getSeconds();
      console.log("this.form.initiationTime:" + this.form.initiationTime); //2019-8-20 03:22:30
    },
    // 将求助信息保存到“待审核”（本地草稿箱）
    saveHelp() {
      alert("saveHelp()");

      // 先执行获取当前时间函数
      this.getInitiationTime();
      alert(
        "getInitiationTime(): this.form.initiationTime: " +
          this.form.initiationTime
      );

      // 定义返回data对象
      let data = {
        buyerId: this.form.buyerId,
        content: this.form.content,
        enterpriseName: "",
        id: this.form.id,
        initiationTime: this.form.initiationTime,
        orderGrabbingNumber: 0,
        region: this.form.region,
        serviceId: null,
        state: "waitingForReleased",
        title: this.form.title,
        type: this.form.type,
      };
      console.log("data.title:" + data.title);
      console.log("data.initiationTime:" + data.initiationTime);

      // 执行获取当前登录用户接口，提取id
      // returnUserInformation().then((resp) => {
      //   console.log("returnUserInformation().then(resp)执行");
      //   console.log("resp: " + resp);
      //   console.log("resp.data.user.id: " + resp.data.user.id);
      //   this.form.buyerId = resp.data.user.id;
      //   console.log("this.form.buyerId: " + this.form.buyerId);
      // });
      // 执行新增求助信息接口（9月25日上午12：20执行到这里就停止了）
      // 【注意】：！
      // （1）该后端接口的时间必须是“2021-9-23 00:00:12”这样的格式！！！
      // （2）serviceProviderId值为 null  !!!!
      // （*可以留意一下console里的执行打印顺序，
      // /api/lawHelp.js里打印在获取即时时间函数后、获取当前用户id前。）
      modifyLegalRecourse(data).then((resp) => {
        console.log("modifyLegalRecourse(data).then(resp)执行");
        console.log("resp: " + resp);
        console.log("resp.data.result: " + resp.data.result);
        console.log("resp.data.message: " + resp.data.message);
        alert("保存成功！");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
// 页头LOGO
.top {
  height: 50px;
  font-size: 30px;
  text-align: center;
  line-height: 50px;
}

// 大盒子
.big-back-box {
  width: 1080px;
  margin: 0 auto;
}

// 原框架自带
.dashboard {
  &-container {
    margin-top: 30px;
    // margin-left: 30px;
    // margin-right: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

// 页脚
.footer {
  height: 300px;
  background-color: blue;
}
.footer-back-box {
  width: 1080px;
  margin-left: 45px;
}
.footer-title {
  height: 30px;
  line-height: 40px;
  padding-left: 10px;
}
.footer-link-card {
  width: 200px;
  background-color: orange;
  margin-left: 10px;
}

// 模板-卡片
.text {
  font-size: 14px;
}
.item {
  padding: 18px 0;
}
.box-card {
  width: 480px;
}
</style>